package entity;

import java.io.Serializable;
import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Transient;

import enumeration.TipoContaEnum;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "tipoConta", discriminatorType = DiscriminatorType.INTEGER)
public class Conta extends EntityManaged implements Serializable {

	private static final long serialVersionUID = 1082824403447060113L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	protected Long id;

	private String nome;

	@Column(columnDefinition="NUMERIC(12, 2)")
	private BigDecimal saldo;

	@Transient
	private BigDecimal saldoCalculado;

	@Column(columnDefinition="NUMERIC(12, 2)")
	private BigDecimal limite;

	@Enumerated(EnumType.ORDINAL)
	private TipoContaEnum tipoConta;

	@Override
	public Long getId() {
		return id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public BigDecimal getSaldo() {
		return saldo;
	}

	public void setSaldo(BigDecimal saldo) {
		this.saldo = saldo;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public BigDecimal getLimite() {
		return limite;
	}

	public void setLimite(BigDecimal limite) {
		this.limite = limite;
	}

	public BigDecimal getSaldoCalculado() {
		return saldoCalculado;
	}

	public BigDecimal getSaldoDisponivel() {
		return saldoCalculado.add(limite);
	}

	public void setSaldoCalculado(BigDecimal saldoCalculado) {
		this.saldoCalculado = saldoCalculado;
	}

	public TipoContaEnum getTipoConta() {
		return tipoConta;
	}

	public void setTipoConta(TipoContaEnum tipoConta) {
		this.tipoConta = tipoConta;
	}
}
